﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="articleCategory.aspx.cs" Inherits="Enterprise.Admin.ArticleCategory" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="tree_list"></table>
    <div id="edit_article_categroy">
        <form id="edit_article_categroy_form" action="Handle/EditArticleCategory.aspx" method="post">
            <p>
                <label>分类名称</label>
                <input type="text" name="CoName" value="" />
                <input type="hidden" name="CoArticleCategoryId" id="edit_article_categroy_id" />
            </p>
            <p class="en-us">
                <label>分类名称(En)</label>
                <input type="text" name="CoNameEn" value="" />

            </p>
            <p>
                <label>父级分类</label>
                <u id="edit_parent_categroy_name"></u>
            </p>
            <p>
                <label>排序</label>
                <input type="text" name="CoSort" value="" />
            </p>

        </form>
    </div>
    <div id="add_article_categroy">
        <form id="add_article_categroy_form" action="Handle/AddArticleCategory.aspx" method="post">
            <p>
                <label>分类名称</label>
                <input type="text" name="CoName" value="" />
            </p>
            <p class="en-us">
                <label>分类名称(En)</label>
                <input type="text" name="CoNameEn" value="" />

            </p>
            <p>
                <label>父级分类</label>
                <u id="add_parent_categroy_name"></u>
                <input type="hidden" name="CoParentId" id="add_parent_id" />
            </p>
            <p>
                <label>排序</label>
                <input type="text" name="CoSort" value="" />
            </p>

        </form>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#tree_list').treegrid({
                url: 'Handle/GetarticleCategoryTreeJson.aspx',
                idField: 'id',
                treeField: 'CoName',
                title: '文章分类列表',
                rownumbers: true,
                fitColumns: true,
                autoRowHeight: false,
                remoteSort: false,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible: true,
                singleSelect: false,
                onClickRow: function () {
                },
                onSelect: function (rowData) {
                    $('#tree_list').treegrid("unselectAll");
                    parentChange(rowData.id, rowData.CoName);
                },
                onSelectAll: function () {
                    $('#tree_list').treegrid("unselectAll");
                },
                onUnselectAll: function () {
                    parentChange('', '根路劲');
                },
                onClickCell: function (field, rowData) {
                  
                },
                onUnselect: function () {
                    $('#tree_list').treegrid("unselectAll");
                    parentChange('', '根路劲');
                },
                columns: [[
                    { title: '类型名称', field: 'CoName', width: 280 },
                    { title: '类型名称(En)', field: 'CoNameEn', width: 280 },
                    {
                        field: 'CoIsSystem',
                        title: '系统项',
                        width: 100,
                        align: 'center',
                        formatter: function (value) {
                            return value == "True" ? '是' : '否';
                        }
                    },
                    { title: '序号', field: 'CoSort', align: 'center', width: 100 },
                    { title: '深度', field: 'CoDepth', align: 'center', width: 60 },
                    {
                        title: '修改',
                        field: 'OpEdit',
                        width: 80,
                        align: 'center',
                        formatter: function (value, rec) {
                            return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';

                        }
                    },
                    {
                        title: '删除',
                        field: 'OpDelete',
                        width: 80,
                        align: 'center',
                        formatter: function (value, rec) {
                            return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                        }
                    },
                    {
                        title: '子类',
                        field: 'OpAddChild',
                        width: 80,
                        align: 'center',
                        formatter: function (value, rec) {
                            return '<a href="javascript:void(0);" mce_href="#" onclick="add(\'' + rec.id + '\',\'' + rec.CoName + '\')">添加</a> ';

                        }
                    }
                ]],
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            add('', '根路劲');
                        } else {
                            add(selectData.id, selectData.CoName);

                        }

                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }

                    }
                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#tree_list').treegrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }
                }]
            });
            $('#add_article_categroy').dialog({
                width: 400,
                height: 250,
                title: '添加文章分类',
                closed: true,
                closable: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_article_categroy').dialog('close');
                    }
                }],
                tools: [{
                    iconCls: 'icon-save',
                    handler: function () {
                        addSave();
                    }
                }]


            });
            $('#edit_article_categroy').dialog({
                width: 400,
                height: 250,
                title: '文章分类修改',
                closed: true,
                closable: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_article_categroy').dialog('close');
                    }
                }],
                tools: [{
                    iconCls: 'icon-save',
                    handler: function () {
                        editSave();
                    }
                }]
            });
            $('#edit_article_categroy_form').form({
                onBeforeLoad: function () { $('#edit_article_categroy').dialog("close"); },
                onLoadSuccess: function (data) {
                    $('#edit_article_categroy').dialog("open");
                    $('#edit_parent_categroy_name').html(data.CoParentName || '根路径');
                },
                onLoadError: function () { $('#edit_article_categroy').dialog("close"); }
            });
        });

        function edit(id) {
            $('#edit_article_categroy_form')[0].reset();
            $('#edit_article_categroy_form').form('load', 'Handle/GetarticleCategoryDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/DeletearticleCategory.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#tree_list").treegrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });
        }

        function parentChange(parentId, parentName) {
            $('#add_parent_categroy_name').html(parentName);
            $('#add_parent_id').val(parentId);
        }
        function add(parentId, parentName) {
            $('#add_article_categroy_form')[0].reset();
            parentChange(parentId, parentName);
            $('#add_article_categroy').dialog('open');
        }
        function addSave() {
            $.ajax({
                type: "POST",
                url: "Handle/AddarticleCategory.aspx",
                data: $("#add_article_categroy_form").serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state)
                        $('#tree_list').treegrid("reload");
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '修改失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/EditarticleCategory.aspx",
                data: $("#edit_article_categroy_form").serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $('#tree_list').treegrid("reload");
                    }

                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '修改失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
</asp:Content>
